XM.lang.namespace('XM.canvas');

/**
 * 图层管理类
 */
XM.canvas.LayerManager = {
    layers: [],
    /**
     * 获取或创建图层
     * @param id {number}
     */
    getLayer: function (id) {
        if (this.layers[id]) {
            return this.layers[id];
        }

        this.layers[id] = new XM.canvas.Layer(id);
    },
    
    /**
     * 批量设置图层
     * @param layers {object|XM.canvas.Layer}
     */
    registerLayers: function (layers) {
        this.layers = layers;
        for (var i = 0, lenOuter = layers.length; i < lenOuter; i++) {
            var layer = layers[i];
            XM.canvas.EventTranslator.parseItems(layer.items);
        }
    },

    /**
     * 根据图层名字获得图层中的物件
     * @param layerName {string}
     */
    getItem: function (layerName) {
        for (var i = 0, len = this.layers.length; i < len; i ++) {
            if (this.layers[i].name === layerName) {
                return this.layers[i].items;
            }
        }
    }
};